<template>
	<view class="flex-col page">

		<view class="flex-col group mt-9">
			<!-- <view class="flex-row justify-between items-center section">
				<view class="flex-row items-center">
					<image class="image_2" src='../../static/icons/location.png' />
					<view class="flex-col items-start ml-17">
						<text class="font text">{{orders.receiverName}},{{orders.receiverPhone}}</text>
						<text class="font_2 text_2 mt-9">{{orders.receiverDistrict}},{{orders.receiverAddress}}</text>
					</view>
				</view>

				<u-icon name="arrow-right"></u-icon>
			</view> -->
			<view class="flex-row items-center section_2 mt-7" @click="goGoods(details.product)">
				<image class="image_4" :src="details.product.meta.imageUrl" />
				<view class="flex-col items-start flex-1 ml-17">
					<text class="font_2 text_3">{{details.product.name}}</text>
					<view class="flex-row" style="padding-top: 20rpx; ">
						<u-avatar size="20" :src="details.buyer.meta.avatar"></u-avatar>
						<view style="font-size: 28rpx; color:#888;">
							{{details.buyer.nickname}}{{details.buyer.mobile}}
						</view>
					</view>
					<!-- 			<view class="flex-row">
						<text class="font text_5">{{details.order.unitPrice}}</text> <text
							style="padding: 5rpx;">x{{details.order.quantity}}</text>
					</view> -->

				</view>
			</view>
			<view class="flex-col section_3 mt-7">
				<view class="flex-row justify-between items-center">
					<text class="font_2 text_6">单号：{{details.order.id}}</text>
					<text class="text_7">{{getOrderStatus(details.status)}}</text>
				</view>
				<!-- 			<view class="flex-row justify-between items-center">
					<text class="font_2 text_6">订单号：{{details.order.id}}</text>
					 
				</view> -->
				<view class="flex-col group_2">
					<view class="flex-row justify-between mt-19">
						<text class="font_2 text_8">经营店铺是否退款</text>
						<text class="font_2 text_9">{{details.firstSellerRefunded?'是':'否'}}</text>
					</view>
					<view class="flex-row justify-between mt-19">
						<text class="font_2 text_8">管理店铺是否退款</text>
						<text class="font_2 text_9">{{details.secondSellerRefunded?'是':'否'}}</text>
					</view>
					<view class="flex-row justify-between mt-19">
						<text class="font_2 text_8">总部是否已收到货,并且已退款</text>
						<text class="font_2 text_9">{{details.headQuarterRefunded?'是':'否'}}</text>
					</view>
					<view class="flex-row justify-between mt-19">
						<text class="font_2">退货数量</text>
						<text class="font_2 text_10">{{details.order.quantity}}</text>
					</view>
					<view class="flex-row justify-between mt-19">
						<text class="font_2">商品总额</text>
						<text class="font_2 text_10"
							style="color: #ff0101;">￥{{details.order.totalPrice?details.order.totalPrice.toFixed(2):'0.00'}}</text>
					</view>
					<view class="flex-row justify-between mt-19">
						<text class="font_2">订单备注</text>
						<text class="font_2 text_10" style="max-width:500rpx ;">{{details.order.remark||'未填写备注'}}</text>
					</view>

					<view class="flex-row justify-between mt-19">
						<text class="font_2">退货原因</text>
						<text class="font_2 text_10"
							style="max-width:500rpx ;">{{details.remarkByBuyer||'未填写退货原因'}}</text>
					</view>
					<view class="flex-row justify-between mt-19" v-if="details.remarkBySeller">
						<text class="font_2">卖家反馈</text>
						<text class="font_2 text_10"
							style="max-width:500rpx ;">{{details.remarkBySeller||'未填写备注'}}</text>
					</view>
				</view>
				<view class="flex-col group_2" v-if="urls1.length>0">
					<view style="padding-bottom: 20rpx;">
						<text style="font-weight: bold;font-size: 28rpx;">图片凭证</text>
					</view>
					<u-album :urls="urls1" keyName="src"></u-album>
				</view>

				<view style="margin-top: 20rpx;" v-if="details.actions.length>0">
					<view style="padding-bottom: 20rpx;">
						<text style="font-weight: bold;font-size: 28rpx;">备注</text>
					</view>
					<view>
						<u-textarea v-model="remark" placeholder="在这里填写备注"
							customStyle="background-color: #f2f2f2"></u-textarea>
					</view>
					<view class="flex-row justify-center items-center " style="margin-top: 20rpx;">

						<button size="mini" type="primary" :disabled="submited" @click="doAction('REJECT',details)"
							style="width: 200rpx; border: 0; background-color: #ff0101;color: #fff;">拒绝</button>
						<button size="mini" type="primary" :disabled="submited" @click="doAction('APPROVE',details)"
							style="width: 200rpx; border: 0; background-color: green;color: #fff;">同意</button>
					</view>

				</view>
				<view v-if="details.instructions&&details.instructions.length>0">
					<view v-for="(item,index) in details.instructions" :key="index" style="padding-top: 20rpx;">
						<view
							style="background-color: #eee; border: 1px solid #eee; padding: 10rpx; border-radius: 10rpx; color: #888;font-size: 28rpx;">
							{{item.content}}
							<view v-if="item.instructionUser"
								style="color: #ff0101; padding: 20rpx 0; font-weight: bold;">
								联系人:{{item.instructionUser.nickname}} {{item.instructionUser.mobile}}
							</view>
	<!-- 						<view v-if="item.instructionUser.meta.paymentText"
								style="color:#000;padding:0 10px; font-size: 28rpx; color: #ff0101; font-weight: bold;">
								银行转账:
								<view style="padding: 20rpx 0; color: #888; font-size: 28rpx;font-weight: normal"
									@click="copyText(item.instructionUser.meta.paymentText)" class="flex-row">
									{{item.instructionUser.meta.paymentText}} <u-icon name="file-text"
										label="复制"></u-icon>
								</view>
							</view> -->
							<image :src="item.instructionUser.meta.qrCode" v-if="item.instructionUser.meta.qrCode"
								style="width: 100%;" mode="widthFix" :show-menu-by-longpres="true"></image>
							<view style="text-align: left; padding: 20px; font-size: 28rpx;">
								提示:长按二维码图片保存到相册后进行识别
								<button type="primary"
									style="width: 200px; line-height:unset; margin:5px auto; font-size:14px;padding: 10px;"
									@click="save(item.instructionUser.meta.qrCode)">保存到相册</button>
							</view>

							<view class="flex-row justify-center" style="padding: 10px;" v-if="item.extraAction">
								<button size="mini" type="primary" :disabled="submited"
									@click="doAction(item.extraAction,details)"
									style="width: 200rpx; border: 0; background-color: #ff0101;color: #fff;">确认</button>
							</view>

						</view>

					</view>
				</view>
			</view>

		</view>
		<u-toast ref="utoast"></u-toast>
	</view>
</template>

<script>
	import Utils from '../../common/Utils';
	export default {
		components: {},
		props: {},
		data() {
			return {
				details: {},
				fileList1: [],
				submited: false,
				remark: "",
				urls1: [],
			};
		},
		onLoad(options) {
			if (options.id) {
				this.getOrderDetails(options.id)
			}
		},
		methods: {
			copyText(text) {
				uni.setClipboardData({
					data: text,
					complete() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			},
			goGoods(goods) {
				uni.navigateTo({
					url: '/pages-publics/GoodsDetails/GoodsDetails?id=' + goods.id
				})
			},

			doAction(action, order) {
				var _that = this;

				uni.showModal({
					content: `确定要执行当前操作?`,
					complete(res) {
						if (res.confirm) {
							_that.$Utils.doAfterOrderAction(order.id, action, _that.remark).then(res => {
								console.log("aaa")
								_that.getOrderDetails(order.id)
							})
						}

					}
				})
			},
			save(url) {
				uni.downloadFile({
					url: url, // 图片的网络URL地址
					success: (downloadResult) => {
						if (downloadResult.statusCode === 200) {
							const tempFilePath = downloadResult.tempFilePath; // 下载后的临时文件路径
							uni.saveImageToPhotosAlbum({
								filePath: tempFilePath,
								success() {
									uni.showToast({
										title: '保存成功',
										icon: 'success',
										duration: 2000
									});
								},
								fail(err) {
									console.error('保存失败:', err);
									uni.showToast({
										title: '保存失败',
										icon: 'none',
										duration: 2000
									});
								}
							});
						} else {
							console.error('下载失败:', downloadResult.errMsg);
						}
					},
					fail(err) {
						console.error('下载失败:', err);
					}
				});
			},



			goBack() {
				uni.navigateBack()
			},
			getOrderBtn(action) {
				return Utils.getOrderBtn(action);
			},
			getOrderStatus(status) {
				return Utils.getAfterStatus(status);
			},
			getOrderDetails(id) {
				this.$get({
					url: `${this.$Utils.ApiUrl}/afterSales/${id}`,
					data: {

					}
				}).then(res => {
					console.log(res)
					this.details = res;
					this.urls1 = [];
					if (res.imageUrl0) {
						this.urls1.push({
							src: res.imageUrl0
						})
					}
					if (res.imageUrl1) {
						this.urls1.push({
							src: res.imageUrl1
						})
					}
					if (res.imageUrl2) {
						this.urls1.push({
							src: res.imageUrl2
						})
					}
					if (res.imageUrl3) {
						this.urls1.push({
							src: res.imageUrl3
						})
					}
					if (res.imageUrl4) {
						this.urls1.push({
							src: res.imageUrl4
						})
					}
					if (res.imageUrl5) {
						this.urls1.push({
							src: res.imageUrl5
						})
					}
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	button {
		border-radius: 30rpx;
		padding: 0 20rpx;
	}

	button:nth-child(1) {
		background-color: #fff;
		color: #666;
	}

	button:nth-child(2) {
		background-color: green;
		color: #ffffff;
	}

	button:nth-child(3) {
		background-color: #ff0101;
		color: #ffffff;
	}

	.mt-9 {
		margin-top: 15.7rpx;
	}

	.mt-7 {
		margin-top: 12.21rpx;
	}

	.mt-19 {
		margin-top: 33.14rpx;
	}

	.ml-17 {
		margin-left: 29.65rpx;
	}

	.page {
		background-color: #f2f2f2;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100%;

		.image {
			width: 100vw;
			height: 25.5814vw;
		}

		.group {
			padding: 0 17.44rpx;

			.section {
				padding: 47.09rpx 27.91rpx;
				background-color: #ffffff;
				border-radius: 17.44rpx;

				.image_2 {
					width: 83.72rpx;
					height: 83.72rpx;
				}

				.text {
					color: #333333;
					line-height: 29.11rpx;
					font-weight: bold;
				}

				.text_2 {
					color: #666655;
					line-height: 22.9rpx;
					font-size: 28rpx;
					word-wrap: break-word;
					width: 70vw;
				}

				.image_3 {
					width: 62.79rpx;
					height: 62.79rpx;
				}
			}

			.section_2 {
				padding: 27.91rpx;
				background-color: #ffffff;
				border-radius: 17.44rpx;

				.image_4 {
					border-radius: 8.72rpx;
					width: 139.53rpx;
					height: 139.53rpx;
				}

				.text_3 {
					color: #575757;
				}

				.text_4 {
					margin-left: 6.98rpx;
					margin-top: 38.37rpx;
					color: #808080;
					line-height: 26.76rpx;
				}

				.text_5 {
					margin-left: 6.98rpx;
					margin-top: 13.95rpx;
					color: #ff0101;
					line-height: 23.83rpx;
				}
			}

			.font_2 {
				font-size: 28rpx;
				font-family: SourceHanSansCN;
				color: #555555;
			}

			.font {
				font-size: 31.4rpx;
				font-family: SourceHanSansCN;
			}

			.section_3 {
				padding: 31.4rpx 27.91rpx 136.05rpx 34.88rpx;
				background-color: #ffffff;
				border-radius: 12.24rpx;

				.text_6 {
					color: #000000;
					line-height: 22.24rpx;
				}

				.text_7 {
					margin-right: 10.47rpx;
					color: #ff0101;
					font-size: 31.4rpx;
					font-family: SourceHanSansCN;
					font-weight: 700;
					line-height: 29.79rpx;
				}

				.group_2 {
					margin-top: 34.88rpx;

					.group_3 {
						padding-left: 6.98rpx;

						.text_8 {
							line-height: 22.66rpx;
						}

						.text_9 {
							color: #ff0101;
							line-height: 18.54rpx;
						}
					}

					.text_10 {
						margin-right: 10.47rpx;
						color: #333333;
						line-height: 22.73rpx;
					}
				}

				.group_4 {
					margin-top: 254.65rpx;
					padding: 0 10.67rpx;

					.text-wrapper {
						padding: 20.93rpx 0;
						background-color: #ffffff;
						border-radius: 33.14rpx;
						width: 211.05rpx;
						height: 68.02rpx;
						border-left: solid 1.74rpx #8a8a8a;
						border-right: solid 1.74rpx #8a8a8a;
						border-top: solid 1.74rpx #8a8a8a;
						border-bottom: solid 1.74rpx #8a8a8a;

						.text_11 {
							color: #383838;
						}
					}

					.text-wrapper_2 {
						padding: 20.93rpx 0;
						background-color: #ff0101;
						border-radius: 33.14rpx;
						width: 209.3rpx;
						height: 66.28rpx;

						.text_12 {
							color: #ffffff;
							line-height: 22.6rpx;
						}
					}
				}
			}
		}
	}
</style>